package com.zlq.cn.controller.sign.driving;


import com.alibaba.fastjson.JSONObject;
import com.zlq.cn.annotations.UnPrintResult;
import com.zlq.cn.api.SignApiResult;
import com.zlq.cn.entity.DrivingCategory;
import com.zlq.cn.entity.DrivingCategoryQuestions;
import com.zlq.cn.entity.DrivingQuestions;
import com.zlq.cn.service.driving.DrivingCategoryQuestionsService;
import com.zlq.cn.service.driving.DrivingCategoryService;
import com.zlq.cn.service.driving.DrivingQuestionsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhoucl
 * @since 2024-10-01
 */
@Api(tags = "驾考")
@RestController
@RequestMapping("/driving")
public class DrivingQuestionsController {

    @Resource
    private DrivingQuestionsService drivingQuestionsService;
    @Resource
    private DrivingCategoryQuestionsService drivingCategoryQuestionsService;
    @Resource
    private DrivingCategoryService drivingCategoryService;

    @UnPrintResult
    @ApiOperation("获取所有题目")
    @PostMapping("/questions/list")
    public SignApiResult<List<DrivingQuestions>> questionsList(@RequestBody JSONObject jsonObject) {
        return SignApiResult.resultSuccess(drivingQuestionsService.list());
    }

    @UnPrintResult
    @ApiOperation("获取所有分类")
    @PostMapping("/category/list")
    public SignApiResult<List<DrivingCategory>> categoryList(@RequestBody JSONObject jsonObject) {
        return SignApiResult.resultSuccess(drivingCategoryService.list());
    }

    @UnPrintResult
    @ApiOperation("获取指定分类下题目")
    @PostMapping("/category/questions")
    public SignApiResult<Set<Integer>> categoryQuestions(@RequestBody DrivingCategory drivingCategory) {
        return SignApiResult.resultSuccess(drivingCategoryQuestionsService.lambdaQuery()
                .eq(DrivingCategoryQuestions::getJoinKey, drivingCategory.getJoinkey())
                .list().stream()
                .map(DrivingCategoryQuestions::getId)
                .collect(Collectors.toSet()));
    }
}

